package LeetCode;

public class Code114_flatten {
    // 把root的右边记录下来，断开，将左边处理完后挂右边，再把原来的右边处理完后接着挂上来
    public void flatten(TreeNode root) {
        if (root == null){
            return;
        }
        flatten(root.left);
        TreeNode right = root.right;
        root.right = root.left;
        root.left = null;
        while (root.right != null){
            root = root.right;
        }
        flatten(right);
        root.right = right;
    }
}
